package part1.api.io.mytest;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class OISDemo {
    public static void main(String[] args) {
        try (
                FileOutputStream fos = new FileOutputStream("student.txt");
                ObjectOutputStream oos = new ObjectOutputStream(fos);
        ) {
            String name = "张三";
            int age = 24;
            String[] otherInfo = {"喜欢打台球", "男", "唱歌"};
            Student zs = new Student(name, age, otherInfo);
            oos.writeObject(zs);

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("序列化写出成功");


        try (
                FileInputStream fis = new FileInputStream("student.txt");
                ObjectInputStream ois = new ObjectInputStream(fis);
        ) {
            Object obj = ois.readObject();
            Student zs1 = (Student) obj;
            System.out.println(zs1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("反序列化读取成功");

    }
}
